package com.example.mhandler;

import android.os.Looper;

import static android.os.Looper.getMainLooper;


public class MyTextView  {
    private static final String TAG = "MyTextView";

    private  Thread mThread;

    public MyTextView() {

        mThread = Thread.currentThread();
    }

    public void  setText(){
        //先检查是否在主线程
        try {
            checkThread();
            System.out.println("更新了UI");
        } catch (Exception e) {
            e.printStackTrace();

        }
    }

    private void checkThread() throws Exception{
        if (mThread!=Thread.currentThread()){
            throw  new Exception("Only the original thread that created a view hierarchy can touch its views.");
        }
    }
    
}